package com.example.neusoft.cook.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.neusoft.cook.R;
import com.example.neusoft.cook.ViewHolder.FooditemViewHolder;
import com.example.neusoft.cook.activity.FoodDetailActivity;
import com.example.neusoft.cook.activity.FoodListActivity;
import com.example.neusoft.cook.base.BaseAcyivity;
import com.example.neusoft.cook.base.BaseListAdapter;
import com.example.neusoft.cook.bean.SampleCook;
import com.example.neusoft.cook.bean.SampleShop;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by neusoft on 2017/5/8.
 */

public class FoodListAdapter extends BaseListAdapter {
    public FoodListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_food_list,parent,false);
        FooditemViewHolder viewHolder = new FooditemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        final SampleCook food = (SampleCook) data.get(position);
        FooditemViewHolder viewHolder = (FooditemViewHolder) holder;
        final String foodName = food.getFoodname();
        int foodPrice = food.getPrice();
        final int foodId = food.getFood_id();
        final int shopId = food.getShop_id();
        String foodIntro = food.getIntro();
        String pic = food.getPic();
        viewHolder.foodNameView.setText(foodName);
        viewHolder.foodPriceView.setText(String.valueOf(foodPrice));
        viewHolder.foodIntroView.setText(foodIntro);
        Picasso.with(context)
                .load(pic)
                .placeholder(R.drawable.ic_cook_holder)
                .error(R.drawable.ic_cook_holder_error)
                .into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity--菜品详情
                Intent intent = new Intent(context, FoodDetailActivity.class);
                intent.putExtra("food_id",foodId);
                intent.putExtra("shop_id",shopId);
                context.startActivity(intent);
            }
        });

    }
}
